import {observable, action, makeAutoObservable, runInAction} from 'mobx';
import {storeSaveListApi} from '../../api/check';
class CheckStore {
  page = 1;
  limit = 10;
  list = [];
  loading = false;
  total = 0;
  constructor() {
    // 将参数对象中的属性设置为 observable state
    // 将参数对象中的方法设置为 action
    makeAutoObservable(this);
  }
  @action getData() {
    console.log('getData');
    this.loading = true;
    try {
      storeSaveListApi({
        page: this.page,
        limit: this.limit,
      }).then(res => {
        const {data, total} = res;
        runInAction(() => {
          this.total = total;
          if (total <= (this.page - 1) * this.limit) {
            return;
          }
          if (this.page === 1) {
            this.list = data;
          } else {
            this.list = this.list.concat(data);
          }
          this.page++;
          this.loading = false;
        });
      });
    } catch (e) {
      console.log(e);
      this.loading = false;
    }
  }
  @action reloadHandle() {
    this.page = 1;
    this.getData();
  }
}
export default new CheckStore();
